package com.sunday.boot3.user.center.rest.api.impl;

import com.sunday.common.core.converter.MapperConvert;
import com.sunday.common.core.remoting.rest.annotation.VoErrorShowType;
import com.sunday.common.core.remoting.rest.page.PageVO;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import com.sunday.boot3.user.center.controller.UserRoleController;
import com.sunday.boot3.user.center.pojo.dto.user.role.RemoveUserRoleReqDTO;
import com.sunday.boot3.user.center.pojo.dto.user.role.SaveUserRoleReqDTO;
import com.sunday.boot3.user.center.pojo.dto.user.role.PageUserRoleReqDTO;
import com.sunday.boot3.user.center.pojo.dto.user.role.UpdateUserRoleReqDTO;
import com.sunday.boot3.user.center.rest.vo.user.role.PageUserRoleResVO;
import com.sunday.boot3.user.center.rest.vo.user.role.RemoveUserRoleReqVO;
import com.sunday.boot3.user.center.rest.vo.user.role.PageUserRoleReqVO;
import com.sunday.boot3.user.center.rest.vo.user.role.SaveUserRoleReqVO;
import com.sunday.boot3.user.center.rest.vo.user.role.UpdateUserRoleReqVO;
import com.sunday.boot3.user.center.rest.api.UserRoleApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 用户角色关系表 Web impl 层
 * @author: zsy
 * @Create: 2024/09/22 16:24:39
 */
@Slf4j
@RestController
@RequestMapping(UserRoleApi.ACCESS_PATH)
@RequiredArgsConstructor
public class UserRoleApiImpl implements UserRoleApi {

    private final UserRoleController userRoleController;

    /**
     * @Description: 新增 用户角色关系表 数据
     * @Param: [saveUserRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse save(SaveUserRoleReqVO saveUserRoleReqVO) {
        return RestResponse.resultReturn(userRoleController.save(MapperConvert.map(saveUserRoleReqVO, SaveUserRoleReqDTO.class)));
    }

    /**
     * @Description: 删除 用户角色关系表 数据
     * @Param: [removeUserRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse remove(RemoveUserRoleReqVO removeUserRoleReqVO) {
        return RestResponse.resultReturn(userRoleController.remove(MapperConvert.map(removeUserRoleReqVO, RemoveUserRoleReqDTO.class)));
    }

    /**
     * @Description: 修改 用户角色关系表 数据
     *
     * @Param: [updateUserRoleReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse update(UpdateUserRoleReqVO updateUserRoleReqVO) {
        return RestResponse.resultReturn(userRoleController.update(MapperConvert.map(updateUserRoleReqVO, UpdateUserRoleReqDTO.class)));
    }

    /**
    * @Description: 获取 用户角色关系表 分页列表数据
    *
    * @Param: [pageUserRoleReqVO]
    * @Return: com.sunday.common.core.remoting.rest.response.RestResponse<com.sunday.common.core.remoting.rest.page.fegin.FeginPageResultVO<com.sunday.boot3.user.center.rest.vo.user.role.PageUserRoleResVO>>
    * @author: zsy
    * @Create: 2024/09/22 16:24:39
    */
    @Override
    @VoErrorShowType(RestResponse.ShowTypeEnum.NOTIFICATION)
    public RestResponse<PageVO<PageUserRoleResVO>> page(PageUserRoleReqVO pageUserRoleReqVO) {
        return RestResponse.convertResultReturn(
                userRoleController.page(MapperConvert.map(pageUserRoleReqVO, PageUserRoleReqDTO.class)),
                body -> PageVO.of(body, PageUserRoleResVO.class));
    }

}